<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表格</title>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/static/css/style.css">
    <link rel="icon" href="__PUBLIC__/static/image/code.png">
</head>
<body class="body">
{if ahuthbtn('add')}
<div><a class="layui-btn site-demo-active layui-btn-sm" href="{:url('admin/Arctype/add')}"><i class="layui-icon">&#xe608;</i>添加分区</a></div>
{/if}
<table class="layui-table" lay-filter="parse-table-demo" id="test33" style="display:none">
    <thead>
    <tr>
        <th lay-data="{field:'id', width:80, sort: true}">id</th>
        <th lay-data="{field:'typename', width:200 }">分类名称</th>
        <th lay-data="{field:'type_img', minwidth:80, sort: true}">图片</th>
        <th lay-data="{field:'status', width:100, templet: '#statusTpl', unresize: true}">状态</th>
        <th lay-data="{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}"">操作</th>
    </tr>
    </thead>
    <tbody>
{foreach $list as $key=>$vo}
    <tr>
        <td>{$vo.id}</td>
        <td>{$vo._name|raw}</td>
        <td>{$vo.type_img}</td>
        <td>{$vo.status}</td>
        <td><a href="{:url('admin/Arctype/add',['id'=>$vo.id])}">添加子栏目</a> | <a href="{:url('admin/Arctype/edit',['id'=>$vo.id])}">修改</a> | <a href="{:url('admin/Arctype/delete',['id'=>$vo.id])}">删去</a></td>
    </tr>
{/foreach}
    </tbody>
</table>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">添加子类</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="statusTpl">
  <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="禁|否" lay-filter="lockstatus" {{ d.status == 0 ? 'checked' : '' }} >
</script>
<script type="text/javascript" src="__PUBLIC__/layui/layui.js"></script>
<script src="__ADMIN__/js/comm.js" charset="utf-8"></script>
<script type="text/javascript">
    // you code ...
layui.use(['form','table','layer','admin'], function(){
  var $ = layui.jquery
      ,form = layui.form
      ,table = layui.table
      ,layer = layui.layer
      ,admin = layui.admin;

      table.init('parse-table-demo', { //转化静态表格
        //height: 'full-500'
      }); 
  //监听工具条
  table.on('tool(parse-table-demo)', function(obj){
    var data = obj.data;
    
    if(obj.event === 'detail'){
      url = "{:url('admin/Arctype/add')}?id="+data.id;
      admin.actAuth(url,function(){
        window.location.href=url ;
      });
      //window.location.href='{:url('admin/Arctype/add')}?id='+data.id ;
    } else if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
        url = "{:url('admin/Arctype/delete')}?id=" + data.id;
        //admin.actAuth(url,function(){
        $.get(url,function(data){
        if (data.code === 0) {
          layer.msg(data.msg);
        }else{
          obj.del();
          layer.msg(data.msg);
        }
        });

        //});

      });
    } else if(obj.event === 'edit'){
      url = "{:url('admin/Arctype/edit')}?id="+data.id;
      admin.actAuth(url,function(){
        window.location.href=url ;
      });
    }
  });



  //监听锁定操作
  form.on('switch(lockstatus)', function(obj){
    if(obj.elem.checked === true){
        isval =0;
    }else{
        isval =1;
    }
    $.post('{:url('admin/Arctype/quickedit')}',{id:this.value,status:isval},function(data,status){
        if(data){
          layer.tips(data.msg,obj.othis);
        }
    });
  });








});
</script>
</body>
</html>